using UniversalAdminSystem.Domian.Core;
using UniversalAdminSystem.Domian.Core.ValueObjects;

namespace UniversalAdminSystem.Domian.LogManagement.Aggregates;

/// <summary>
/// 日志条目聚合根
/// </summary>
public class LogEntry : AggregateRoot
{
    public Guid Id { get; private set; }
    public string Level { get; private set; }
    public string Message { get; private set; }
    public string Source { get; private set; }
    public UserId? UserId { get; private set; }
    public DateTime Timestamp { get; private set; }
    public string? Context { get; private set; }
    public string? Exception { get; private set; }

    private LogEntry() { }

    public static LogEntry Create(
        string level,
        string message,
        string source,
        UserId? userId = null,
        string? context = null,
        string? exception = null)
    {
        if (string.IsNullOrWhiteSpace(level))
            throw new ArgumentException("日志级别不能为空", nameof(level));

        if (string.IsNullOrWhiteSpace(message))
            throw new ArgumentException("日志消息不能为空", nameof(message));

        if (string.IsNullOrWhiteSpace(source))
            throw new ArgumentException("日志来源不能为空", nameof(source));

        return new LogEntry
        {
            Id = Guid.NewGuid(),
            Level = level,
            Message = message,
            Source = source,
            UserId = userId,
            Timestamp = DateTime.UtcNow,
            Context = context,
            Exception = exception
        };
    }
} 